package com.info.controller;

import com.common.MyPage;
import com.common.MyPageImpl;
import com.common.PagedResult;
import com.common.aop.LoggerManage;
import com.info.InfoQueryCondition;
import com.info.domain.Info;
import com.info.export.InfoExportExcel;
import com.info.service.InfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by sola on 2017/9/23.
 */
@RestController
@RequestMapping(value = "/infoController")
public class InfoController {

    private InfoService infoService;

    @Autowired
    public InfoController(InfoService infoService) {
        this.infoService = infoService;
    }

    @RequestMapping(value = "/infoadd" ,method = {RequestMethod.POST,RequestMethod.GET})
    @LoggerManage(description = "infoadds")
    public void addUser(HttpServletRequest httpRequest, HttpServletResponse httpResponse){
        PagedResult<Info> infoPage = infoService.findAll(new InfoQueryCondition(1,30000));
        System.out.print("infoadds");
    }

    @RequestMapping(value = "/info/excelexport" ,method = RequestMethod.GET)
    //@LoggerManage(description = "excelexport")
    public void exportInfoExcel(HttpServletRequest httpRequest, HttpServletResponse httpResponse){
        PagedResult<Info> infoPage = infoService.findAll(new InfoQueryCondition(1,155000));
        List<Info> infoList = infoPage.getRows();
        InfoExportExcel infoExportExcel = new InfoExportExcel(infoList);
        infoExportExcel.write(httpResponse,true);
        System.out.print("ok");
    }
}
